<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .big{
            font-size: 30px;
        }
    </style>
</head>

<body>
<!-- 
    Ele.classList.add()  新增标签名
    Ele.classList.remove() 删除标签名
    Ele.classList.contains() 查询是否包含该标签名
    Ele.classList.toggle()  切换/转变 -->  


    
    <p class="p1">这是一个P标签</p>
    <button onclick="addDanger()">这是增加danger</button>
    <button onclick="removeDanger()">这是移除danger</button>
    <button onclick="toggleBig()">改变大小</button>
    <script>
        var p1Ele = document.querySelector('.p1')
        function addDanger() {
            p1Ele.classList.add('danger');
        }
        function removeDanger() {
            if(p1Ele.classList.contains('danger')){p1Ele.classList.remove('danger');}
            else{
                alert('没有danger标签名');
            }
        }
        function toggleBig(){
            p1Ele.classList.toggle('big');
        }

    </script>
</body>

</html>